package com.qlogic.commons.utils.os;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import com.qlogic.commons.utils.strings.StringUtils;

public class DefaultOsCommandResultFormater implements OsCommandResultFormater {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6789991520573665040L;

	public InputStream format (String command, OsCommandResult osCommandResult) {
		try {
			ByteArrayOutputStream baos = new ByteArrayOutputStream ();
			baos.write (("Command [" + command + "] results : " + StringUtils.LINE_SEP).getBytes ("UTF-8"));
			for (int i = 0; i < osCommandResult.getRowsCount (); i++) {
				baos.write (osCommandResult.getRow (i).getBytes ("UTF-8"));
				baos.write (StringUtils.LINE_SEP.getBytes ());
				baos.flush ();
			}
			InputStream is = new ByteArrayInputStream (baos.toByteArray ());
			baos.close ();
			return is;
		} catch (IOException ioex) {
		}
		return null;
	}
}
